<template>
	<div class="app-container">
		<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
			<el-form-item label="文件标题" prop="rfileTitle">
				<el-input v-model="queryParams.rfileTitle" placeholder="请输入文件标题" clearable @keyup.enter.native="handleQuery" />
			</el-form-item>
			<el-form-item label="上传日期" prop="rfileDate">
				<el-date-picker clearable v-model="queryParams.rfileDate" type="date" value-format="yyyy-MM-dd" placeholder="请选择文件上传日期">
				</el-date-picker>
			</el-form-item>
			<!-- <el-form-item label="文件类型" prop="rfileType">
				<el-select v-model="queryParams.rfileType" placeholder="请选择文件类型" clearable @keyup.enter.native="handleQuery">
					<el-option value="doc文档">doc文档</el-option>
					<el-option value="xls数据表">xls数据表</el-option>
					<el-option value="txt记事本">txt记事本</el-option>
					<el-option value="pdf文件">pdf文件</el-option>
					<el-option value="ppt演示文档">ppt演示文档</el-option>
				</el-select>
				<!-- <el-input v-model="queryParams.rfileTitle" placeholder="请输入文件标题" clearable @keyup.enter.native="handleQuery" /> -->
			</el-form-item> -->
			<el-form-item>
				<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
				<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
			</el-form-item>
		</el-form>

		<el-row :gutter="10" class="mb8">
			
			<el-col :span="1.5">
				<el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['staff:rfile:export']">导出</el-button>
			</el-col>
			<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
		</el-row>

		<el-table v-loading="loading" :data="rfileList" @selection-change="handleSelectionChange">
			<el-table-column type="selection" width="55" align="center" />
			
			<el-table-column label="文件标题" align="center" prop="rfileTitle" >
				<template slot-scope="scope">
					<el-link :href="`${baseUrl}${scope.row.rfilePath}`" :underline="false" target="_blank">
						 <span>{{scope.row.rfileTitle}}</span>
					</el-link>
				</template>
			</el-table-column>
			<el-table-column label="文件下载" align="center" prop="rfilePath" >
				<template slot-scope="scope">
					<el-link :href="`${baseUrl}${scope.row.rfilePath}`" :underline="false" target="_blank">
						 <span style="color: #007AFF;">下载</span>
					</el-link>
				</template>
			</el-table-column>
			<!-- <el-table-column label="文件类型" align="center" prop="rfileType" /> -->
			<el-table-column label="文件上传日期" align="center" prop="rfileDate" width="180">
				<template slot-scope="scope">
					<span>{{ parseTime(scope.row.rfileDate, '{y}-{m}-{d}') }}</span>
				</template>
			</el-table-column>
			
		</el-table>

		<pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
		 @pagination="getList" />

		
	</div>
</template>

<script>
	import {
	listRfile
} from "@/api/staff/rfile";

	export default {
		name: "Rfile",
		data() {
			return {
				baseUrl:process.env.VUE_APP_BASE_API,
				// 遮罩层
				loading: true,
				// 选中数组
				ids: [],
				// 非单个禁用
				single: true,
				// 非多个禁用
				multiple: true,
				// 显示搜索条件
				showSearch: true,
				// 总条数
				total: 0,
				// 文件管理表格数据
				rfileList: [],
				// 弹出层标题
				title: "",
				// 是否显示弹出层
				open: false,
				// 查询参数
				queryParams: {
					pageNum: 1,
					pageSize: 10,
					rfileTitle: null,
					rfilePath: null,
					rfileType: null,
					rfileDate: null
				},
				// 表单参数
				form: {},
				// 表单校验
				rules: {
					rfileTitle: [{
						required: true,
						message: "文件标题不能为空",
						trigger: "blur"
					}],
					rfilePath: [{
						required: true,
						message: "文件路径不能为空",
						trigger: "blur"
					}],
					// rfileType: [{
					// 	required: true,
					// 	message: "文件类型不能为空",
					// 	trigger: "change"
					// }],
					rfileDate: [{
						required: true,
						message: "文件上传日期不能为空",
						trigger: "blur"
					}]
				}
			};
		},
		created() {
			this.getList();
		},
		methods: {
			/** 查询文件管理列表 */
			getList() {
				this.loading = true;
				listRfile(this.queryParams).then(response => {
					this.rfileList = response.rows;
					this.total = response.total;
					this.loading = false;
				});
			},
			// 取消按钮
			cancel() {
				this.open = false;
				this.reset();
			},
			// 表单重置
			reset() {
				this.form = {
					rfileId: null,
					rfileTitle: null,
					rfilePath: null,
					rfileType: null,
					rfileDate: null
				};
				this.resetForm("form");
			},
			/** 搜索按钮操作 */
			handleQuery() {
				this.queryParams.pageNum = 1;
				this.getList();
			},
			/** 重置按钮操作 */
			resetQuery() {
				this.resetForm("queryForm");
				this.handleQuery();
			},
			// 多选框选中数据
			handleSelectionChange(selection) {
				this.ids = selection.map(item => item.rfileId)
				this.single = selection.length !== 1
				this.multiple = !selection.length
			},
			
			/** 导出按钮操作 */
			handleExport() {
				this.download('staff/rfile/export', {
					...this.queryParams
				}, `rfile_${new Date().getTime()}.xlsx`)
			}
		}
	};
</script>
